package com.augurit.wf.client.remind.convert;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.augurit.common.util.lang.DateUtils;
import com.augurit.wf.client.remind.web.form.WfRemindForm;
import com.augurit.wf.common.entity.WfRemind;

public class WfRemindConvertor {
	public static WfRemindForm convertVoToForm(WfRemind entity) {
		if(entity != null) {
			WfRemindForm form = new WfRemindForm();
			form.setId(entity.getId());
			form.setWfInstanceId(entity.getWfInstanceId());
			form.setActivityName(entity.getActivityName());
			form.setReminder(entity.getReminder());
			form.setReminderName(entity.getReminderName());
			form.setRemindDate(entity.getRemindDate());
			form.setContent(entity.getContent());
			
			form.setSendEmail(entity.getSendEmail());
			form.setSendSms(entity.getSendSms());
			form.setAssignee(entity.getAssignee());
			form.setAssigneeName(entity.getAssigneeName());
			return form;
		}else
			return null;
	}
	
	public static void convertFormToVo(WfRemindForm form, WfRemind entity) {
		if(entity != null && form != null) {
			entity.setId(form.getId());
			if(form.getWfInstanceId() != null && form.getWfInstanceId().trim().length() > 0)
				entity.setWfInstanceId(form.getWfInstanceId().trim());
			if(form.getActivityName() != null && form.getActivityName().trim().length() > 0)
				entity.setActivityName(form.getActivityName().trim());
			if(form.getReminder() != null && form.getReminder().trim().length() > 0)
				entity.setReminder(form.getReminder().trim());
			if(form.getReminderName() != null && form.getReminderName().trim().length() > 0)
				entity.setReminderName(form.getReminderName());
			entity.setRemindDate(form.getRemindDate());
			if(form.getContent() != null && form.getContent().trim().length() > 0)
				entity.setContent(form.getContent().trim());
			
			if(form.getAssignee() != null && form.getAssignee().trim().length() > 0){
				entity.setAssignee(form.getAssignee());
			}
			if(form.getAssigneeName() != null && form.getAssigneeName().trim().length() > 0){
				entity.setAssigneeName(form.getAssigneeName());
			}
			
			if(form.getSendEmail() != null && form.getSendEmail().trim().length() > 0){
				entity.setAssignee(form.getAssignee());
			}
			if(form.getSendSms() != null && form.getSendSms().trim().length() > 0){
				entity.setSendSms(form.getSendSms());
			}
		}
	}
	
	public static List<WfRemindForm> convertVoListToFormList(List<WfRemind> wfRemindList) {
		if(wfRemindList != null && wfRemindList.size() > 0) {
			List<WfRemindForm> wfRemindFormList = new ArrayList();
			for(int i=0; i<wfRemindList.size(); i++) {
				wfRemindFormList.add(convertVoToForm(wfRemindList.get(i)));
			}
			return wfRemindFormList;
		}
		return null;
	}
	
	public static List<Map> convertVoListToMapList(List<WfRemind> wfRemindList) {
		if(wfRemindList != null && wfRemindList.size() > 0) {
			List<Map> mapList = new ArrayList();
			for(int i=0; i<wfRemindList.size(); i++) {
				WfRemind entity = wfRemindList.get(i);
				Map<String, String> map = new HashMap();

				map.put("id", entity.getId() == null ? "" : entity.getId().toString());
				map.put("wfInstanceId", entity.getWfInstanceId());
				map.put("activityName", entity.getActivityName());
				map.put("reminder", entity.getReminder());
				map.put("remindDate", DateUtils.dateTimeToString(entity.getRemindDate(), "yyyy-MM-dd"));
				map.put("content", entity.getContent());
				
				mapList.add(map);
			}
			return mapList;
		}
		return null;
	}
	
	public static List<WfRemind> convertFormListToVoList(List<WfRemindForm> wfRemindFormList) {
		if(wfRemindFormList != null && wfRemindFormList.size() > 0) {
			List<WfRemind> wfRemindList = new ArrayList();
			for(int i=0; i<wfRemindFormList.size(); i++) {
				WfRemind wfRemind = new WfRemind();
				convertFormToVo(wfRemindFormList.get(i), wfRemind);
				wfRemindList.add(wfRemind);
			}
			return wfRemindList;
		}
		return null;
	}
}